#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author Jmz


info = {'name':'jmz','age':25,'sex':'man'}
# info = dict({'name':'jmz','age':25,'sex':'man'})
# info = dict(name='jmz',age=25,sex='man')
# info = dict([['name','jmz'],('age',25),['sex','man']])

# print(info,type(info))


for k in info:    # 循环key
    print(k,info[k])

'''
name jmz
age 25
sex man
'''
for k in info.keys():
    print(k)
'''
name
age
sex
'''
for v in info.values():
    print(v)
'''
jmz
25
man
'''
for v in info.items():
    print(v)
'''
('name', 'jmz')
('age', 25)
('sex', 'man')
'''

for k,v in info.items():
    print(k,v)
'''
name jmz
age 25
sex man
'''




print('和平的分割线'.center(100,'-'))

# 判断是否存在某个key,    in  | not in
if 'name' in info:
    print('存在name 这个key ')

print(len(info))





print('增删改    和平的分割线'.center(100,'-'))

# 增

info['school'] = '上海啦啦啦'
info.setdefault('obj','上海华为')    # 无责增加 ，有则不改
print(info)
#{'name': 'jmz', 'age': 25, 'sex': 'man', 'school': '上海啦啦啦', 'obj': '上海华为'}

# 改
info['school'] = '南京理工'
dic = {
    'name':'陌语',
    'age':18,
    'addr':'北京'
}

info.update(dic)   #    有则改之，无则增加

print(info)
#{'name': '陌语', 'age': 18, 'sex': 'man', 'school': '南京理工', 'obj': '上海华为', 'addr': '北京'}


# 删
info.pop('name')  # 知道删
info.popitem()    # 随机删
print(info)
# {'age': 18, 'sex': 'man', 'school': '南京理工', 'obj': '上海华为'}



# 查
if 'sex' in info:
    print('键存在')

print(info.get('obj'))   # 有则返回， 无则None
